package com.universest.swordholder.ui.widget

import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.scrollable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import dev.jeziellago.compose.markdowntext.MarkdownText

@Composable
fun AiAnswerDialog(
    onDismiss: () -> Unit,
    content: String
) {
    CardDialog{
        Column(horizontalAlignment = Alignment.CenterHorizontally ) {
            val scroll = rememberScrollState()
            Box(modifier = Modifier
                .height(300.dp)
                .verticalScroll(scroll))
                    {
                MarkdownText(
                    modifier = Modifier
                        .padding(15.dp)
                        .fillMaxWidth()
                        .wrapContentHeight(),
                    markdown =  content)
            }
            Button(
                onClick = { onDismiss() },
                modifier = Modifier
                    .padding(8.dp)
            ) {
                Text("确定")
            }
        }

    }
}

@Composable
@Preview
fun AiAnswerDialogPreview(){
    AiAnswerDialog(
        onDismiss = {},
        content = "### 提示词生成结果\n" +
                "\n" +
                "- 1. 创建一个名为`prompt.txt`的文件，将提示词复制进去。\n" +
                "- 2. 运行`python generate_prompt.py`命令，生成`prompt.txt`文件。\n" +
                "- 3. 运行`python generate_images.py`命令，生成图片。\n"
    )
}